package com.geologyoa.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.DecimalFormat;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.XMLWriter;

import com.geologyoa.domain.Dwqk01;
import com.geologyoa.domain.Wpdj01;
import com.geologyoa.domain.Wpfj01;
import com.geologyoa.service.SystemManager;
import com.geologyoa.service.SystemManagerImpl;

public class searchWdfj01Servlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
          doPost(request,response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		SystemManager sys=new SystemManagerImpl();
		Wpfj01 wpfj01=new Wpfj01();
		String xmName = request.getParameter("pgbgName");//评估报告名称
		String wdName = request.getParameter("fjName");//附件名称
		String wdType = request.getParameter("wdType");//文档类别 0 1 2 3 4 5 
		
		 List<Wpfj01> list=sys.SearchWpfj(xmName,wdName,wdType);
		 Document document=DocumentHelper.createDocument();
			if(list!=null)
			{
				Element fwlistElement =document.addElement("wpfjList");
				fwlistElement.addAttribute("size", (new StringBuilder(String.valueOf(list.size()))).toString());
				Wpfj01 wpfj;
				Element fwElement;
				for(Iterator iterator=list.iterator();iterator.hasNext();)
				{
					wpfj = (Wpfj01)iterator.next();
					if(wpfj.getType()==null)
						continue;
					fwElement=fwlistElement.addElement("wpfjInfo");
					
					fwElement.addAttribute("WPFJ0101", wpfj.getWpfj0101().toString());
					fwElement.addAttribute("WPFJ0102", wpfj.getWpfj0102());
					fwElement.addAttribute("WPFJ0103", wpfj.getWpfj0103());
					fwElement.addAttribute("WPFJ0106", wpfj.getWpfj0106());
					fwElement.addAttribute("TYPE", wpfj.getType());
				}
			}
			StringWriter xmlout = new StringWriter();
			XMLWriter output = new XMLWriter(xmlout);
			output.write(document);
			response.setContentType("text/html;charset=utf-8");
			response.setHeader("Cache-Control", "no-cache");
			response.setHeader("Expires", "0");
			response.setHeader("Pragma", "No-cache");
			response.getWriter().write(xmlout.toString());
	}

}
